<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<!--head部分-->
<head th:include="layout :: htmlhead" th:with="title='后台管理'">
</head>
<body class="layui-layout-body">
    <div class="layui-layout layui-layout-admin">
        <!--头-->
        <div th:replace="fragments/head :: header"></div>
        <div class="layui-body" style="margin-left: 50px;margin-right: 50px;">
        
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;width: 80%;">
  <legend>${comment}列表</legend>
</fieldset>
    <div class="layui-btn-group">
        <button class="layui-btn" id="btn-new" onclick="newFunction()">新增${comment}</button>
    </div>
<table class="layui-table" lay-data="{url:'getByPage', page:true,id:'test3',cellMinWidth:80}" lay-filter="test3" style="width: 20%;">
  <thead>
    <tr>
    <#list columns as col>
	    <#if (!col.primaryKey)&& (col.comment!='') >
    	<th lay-data="{field:'${col.columnJavaName}'}">${col.comment}</th>
	    </#if>
    </#list>
		<th lay-data="{fixed: 'right', width: 165, align:'center', toolbar: '#barDemo'}"> </th>
    </tr>
  </thead>
</table>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
layui.use('table', function(){
  var table = layui.table;
  var $ = layui.jquery;
  
  //监听工具条
  table.on('tool(test3)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
    var data = obj.data //获得当前行数据
    ,layEvent = obj.event; //获得 lay-event 对应的值
    <#list columns as col>
	    <#if col.primaryKey >
    var id = data.${col.columnJavaName};
	    </#if>
    </#list>
    if(layEvent === 'detail'){
      window.location='detailPage.html?id='+id;
    } else if(layEvent === 'del'){
        layer.confirm('真的删除行么', function(index){
          //向服务端发送删除指令
          $.get("delete",{id:id},function(data){
          	if(data==1) {
          		table.reload('test3');
          	}else {
          		layer.msg('删除失败');
          	}
          });
        });
    } else if(layEvent === 'edit'){
      window.location='dataPage.html?id='+id;
    }
  });
});
function newFunction(){
	  window.location='dataPage.html';
}
</script>
        </div>
        <!--底部-->
        <div th:replace="fragments/footer :: footer"></div>
    </div>
</body>
</html>